home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
MoreKittiesPlease
/
Source
/
FragUtils.c
< prev
next >
Wrap
Text File
|
2000-06-23
|
3KB
|
106 lines
/*
File: FragUtils.c
Contains: CFM library access to resources.
Written by: Quinn "The Eskimo!"
Copyright: © 1998 by Apple Computer, Inc., all rights reserved.
Change History (most recent first):
You may incorporate this sample code into your applications without
restriction, though the sample code has been provided "AS IS" and the
responsibility for its operation is 100% yours. However, what you are
not permitted to do is to redistribute the source as "DSC Sample Code"
after having made changes. If you're going to re-distribute the source,
we require that you make it clear in the source that the code was
descended from Apple Sample Code, but that you've made changes.
*/
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// OT Stuff
#import <OTDebug.h>
/////////////////////////////////////////////////////////////////////
// Our prototypes
#import "FragUtils.h"
/////////////////////////////////////////////////////////////////////
// The following has disappeared from Universal Interfaces 3.1
// but it is so wonderfully useful.
#if UNIVERSAL_INTERFACES_VERSION >= 0x0300
#define IsFileLocation(where) \
( ((where) == kDataForkCFragLocator) || \
((where) == kResourceCFragLocator) )
#endif
/////////////////////////////////////////////////////////////////////
static AliasHandle gAliasToLibraryFile = nil;
// ••• need to explicitly preserve CurResFile in this and all its clients
extern OSStatus FUOpenResourceFork(SInt16 *refNum)
{
OSStatus err;
Boolean junkWasChanged;
FSSpec fss;
*refNum = 0;
err = noErr;
if (gAliasToLibraryFile == nil) {
err = fnfErr;
}
if (err == noErr) {
err = ResolveAlias(nil, gAliasToLibraryFile, &fss, &junkWasChanged);
}
if (err == noErr) {
// By opening the resource file read-only, we ensure
// that we *alway* get our own copy of the resource map,
// so we can close it safely when we're done. See
// DTS Technote 1••• "OpenResFile Twice Considered Hard" for
// details.
*refNum = FSpOpenResFile(&fss, fsRdPerm);
err = ResError();
OTAssert("FUOpenResourceFork: FSpOpenResFile misbehaving", err != noErr || *refNum != 0);
}
return err;
}
extern OSStatus FUInitialise(const CFragInitBlock *theInitBlock)
{
OSStatus err;
// OTAssert("FUInitialise: Not in system heap!", GetZone() == SystemZone());
err = noErr;
if ( IsFileLocation(theInitBlock->fragLocator.where) ) {
err = NewAlias(nil, theInitBlock->fragLocator.u.onDisk.fileSpec, &gAliasToLibraryFile);
OTAssert("FUInitialise: NewAlias misbehaving", err != noErr || gAliasToLibraryFile != nil);
}
OTAssert("FUInitialise: Error creating alias to library file", err == noErr);
return err;
}
extern void FUTerminate(void)
{
if (gAliasToLibraryFile != nil) {
DisposeHandle( (Handle) gAliasToLibraryFile);
OTAssert("FUTerminate: Error disposing alias", MemError() == noErr);
gAliasToLibraryFile = nil;
}
}